﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PACS.Data;
using System.Data;

namespace WoSoft.PACS.Data.TemplateData
{
    /// <summary>
    /// 词句管理
    /// </summary>
    public class OutlineWordsDataService : Db
    {
        /// <summary>
        /// 插入词句
        /// </summary>
        /// <param name="cid">分类ID</param>
        /// <param name="name">词句名称</param>
        /// <param name="comment">备注</param>
        /// <param name="content">词句内容</param>
        /// <returns></returns>
        public int Insert(string cid, string name, string comment, string content)
        {
            return this.SqlDatabase.Insert("报告词句")
                .Column("ID", Guid.NewGuid().ToString())
                .Column("分类ID", cid)
                .Column("名称", name)
                .Column("注释", comment)
                .Column("内容", content)
                .Execute();
        }

        /// <summary>
        /// 执行更新
        /// </summary>
        /// <param name="id">ID</param> 
        /// <param name="name">名称</param>
        /// <param name="comment">注释</param>
        /// <param name="content">内容</param>
        /// <returns></returns>
        public int Update(string id, string name, string comment, string content)
        {
            return this.SqlDatabase.Update("报告词句")
                .Column("名称", name)
                .Column("注释", comment)
                .Column("内容", content)
                .Where("ID", id)
                .Execute();
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Delete(string id)
        {
            return this.SqlDatabase.Sql("DELETE  dbo.报告词句 where ID=@ID")
                .Parameter("ID", id)
                .Execute();
        }

        /// <summary>
        /// 根据ID查询单记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataTable GetModelByID(string id)
        {
            return this.SqlDatabase.Sql("select * from 报告词句 where ID = @ID")
                .Parameter("ID", id)
                .QuerySingle<DataTable>();
        }

        /// <summary>
        /// 根据分类获取该分类所有分类ID
        /// </summary>
        /// <param name="cid"></param>
        /// <returns></returns>
        public DataTable GetModesByCID(string cid)
        {
            return this.SqlDatabase.Sql("select ID,名称,内容,注释 from 报告词句 where 分类ID = @分类ID")
                           .Parameter("分类ID", cid)
                           .QuerySingle<DataTable>();
        }
    }
}
